<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>开立订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input id="cname" type="text" name="cname" lay-verify="required" lay-reqtext="商品名称不能为空" placeholder="请输入商品名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">商品类别</label>
        <div class="layui-input-block">
            <select id="tid" name="tid">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">价格</label>
        <div class="layui-input-block">
            <input id="price" type="number" name="price" lay-verify="required" lay-reqtext="价格不能为空" placeholder="请输入价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">数量</label>
        <div class="layui-input-block">
            <input id="num" type="text" name="num" lay-verify="required" lay-reqtext="数量不能为空" placeholder="请输入数量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">计价单位</label>
        <div class="layui-input-block">
            <input id="mbig" type="text" name="mbig" lay-verify="required" lay-reqtext="计价单位不能为空" placeholder="请输入计价单位" value="" class="layui-input">
            <tip>指包含物品的容器的计量单位</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">所含个数</label>
        <div class="layui-input-block">
            <input id="scale" type="number" name="scale" lay-verify="required" lay-reqtext="所含个数不能为空" placeholder="请输入所含个数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">产品单位</label>
        <div class="layui-input-block">
            <input id="mlittle" type="text" name="mlittle" lay-verify="required" lay-reqtext="产品单位不能为空" placeholder="请输入产品单位" value="" class="layui-input">
            <tip>指所含物品的计量单位</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">供应商</label>
        <div class="layui-input-block">
            <select id="sid" name="sid">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="${pageContext.request.contextPath}../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            laydate = layui.laydate;

        function tidPost(callback) {
            $.ajax({
                method: "POST",
                url:"/indent/classifylist",
                success: function (result) {
                    if (!result.IsError) {
                        for (var num=0;num<result.data.length;num++){
                            $('#tid').append(new Option(text= result.data[num].tname,value=result.data[num].tid));
                        }
                        layui.form.render();
                        if (typeof callback === "function") {
                            callback();
                        }
                    }
                    else {
                        layer.msg(result.Message);
                    }
                },
                dataType:"JSON",
                error: function (error) {
                    layer.msg("服务器错误！");
                }
            });
        }

        function sidPost(callback) {
            $.ajax({
                method: "POST",
                url:"/suppiler/list",
                success: function (result) {
                    if (!result.IsError) {
                        for (var num=0;num<result.data.length;num++){
                            $('#sid').append(new Option(text= result.data[num].firm,value=result.data[num].sid));
                        }
                        layui.form.render();
                        if (typeof callback === "function") {
                            callback();
                        }
                    }
                    else {
                        layer.msg(result.Message);
                    }
                },
                dataType:"JSON",
                error: function (error) {
                    layer.msg("服务器错误！");
                }
            });
        }
        tidPost();
        sidPost();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index=JSON.stringify(data.field)
            $.post(
                "/indent/add",{
                    indentlist:index
                },function (d) {
                   if (d=="true"){
                       layer.msg("订单提交成功，请等待审批完成",function () {
                           location.reload()
                       })
                   }else {
                       layer.msg("订单提交失败")
                   }

                }
            )

            return false;
        });


    });
</script>
</body>
</html>